#include "utils.h"

#ifdef _WIN32
	#include <Windows.h>
	char* UTF8ToMB(const char* pu8, int utf8Len)
	{
		// convert an UTF8 string to widechar
		size_t nLen = MultiByteToWideChar(CP_UTF8, 0, pu8, utf8Len, NULL, 0);
		wchar_t *lpszW = new wchar_t[nLen + 1];
		*(lpszW + nLen) = 0;
		size_t nRtn = MultiByteToWideChar(CP_UTF8, 0, pu8, utf8Len, lpszW, nLen);

		// convert an widechar string to Multibyte   
		size_t MBLen = WideCharToMultiByte(CP_ACP, 0, lpszW, nLen, NULL, 0, NULL, NULL);
		char* pmb = new char[MBLen + 1];
		*(pmb + MBLen) = 0;
		nRtn = WideCharToMultiByte(CP_ACP, 0, lpszW, nLen, pmb, MBLen, NULL, NULL);
		delete[] lpszW;

		return pmb;
	}

#else
	char* UTF8ToMB(const char* pu8, int utf8Len) {
		return (char*)pu8;
	}
#endif